package com.edu.exam.enums.exam;

import com.edu.exam.enums.core.StatusEnum;

/**
 * 试题状态枚举
 */
public enum QuestionStatus implements StatusEnum {

    DRAFT("DRAFT", "草稿"),
    PENDING_REVIEW("PENDING_REVIEW", "待审核"),
    APPROVED("APPROVED", "已批准"),
    REJECTED("REJECTED", "已拒绝"),
    ACTIVE("ACTIVE", "启用"),
    INACTIVE("INACTIVE", "停用"),
    ARCHIVED("ARCHIVED", "已归档");

    private final String code;
    private final String description;

    QuestionStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     */
    public static QuestionStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return DRAFT;
        }

        for (QuestionStatus value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return DRAFT;
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，null如果未找到
     */
    public static QuestionStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (QuestionStatus value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}